home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 116 / MacAddict 116 (Mac Power Pack)(theDISC)(April 2006).iso / Software / Internet & Communication / Jon's Phone Tool.dmg / Goodies / JPT FileMaker Pro Examples / JPT FileMaker Pro Example.applescript < prev   
Text File  |  2005-12-20  |  4KB  |  129 lines

  1. (*
  2. This script will ask you to identify a cell in your current FileMaker Pro record and use the contents of that cell as a number to dial via Jon's Phone Tool (it will also ask for the cell to use as the name of the contact to dial). Once you choose the cell names, the application will continue to use those cell names unless the there is an error (such as the cell doesn't exist in the current record or the cell is empty in the current record).
  3. *)
  4.  
  5. property phone_cell_name : ""
  6. property name_cell_name : ""
  7.  
  8. if phone_cell_name = "" then
  9.     set the_result to my choose_cell("the phone number")
  10.     if the_result = false then return
  11.     set phone_cell_name to the_result
  12. end if
  13.  
  14. if name_cell_name = "" then
  15.     set the_result to my choose_cell("the name")
  16.     if the_result = false then return
  17.     set name_cell_name to the_result
  18. end if
  19.  
  20. set the_number to get_cell_value(phone_cell_name, "Phone")
  21. if the_number = false then
  22.     set phone_cell_name to ""
  23.     return
  24. end if
  25.  
  26. set the_name to get_cell_value(name_cell_name, "Name")
  27. if the_name = false then
  28.     set name_cell_name to ""
  29.     return
  30. end if
  31.  
  32. my dial_number(the_number, the_name)
  33.  
  34. --*********************************************************************************--
  35. --*********************************************************************************--
  36.  
  37. on dd(the_message, the_buttons, default_button, the_icon, giving_up)
  38.     activate
  39.     if the_icon = 0 then beep
  40.     if giving_up = false then
  41.         display dialog the_message buttons the_buttons default button default_button with icon the_icon
  42.     else
  43.         display dialog the_message buttons the_buttons default button default_button with icon the_icon giving up after 10
  44.     end if
  45. end dd
  46.  
  47. on get_cell_value(the_cell_name, the_label)
  48.     try
  49.         tell application "FileMaker Pro" to set the_value to cellValue of cell the_cell_name of current record
  50.     on error the_error
  51.         my dd(the_error, {"OK"}, 1, 0, true)
  52.         return false
  53.     end try
  54.     if the_value = "" and the_label = "Phone" then
  55.         my dd("The cell \"" & the_cell_name & "\" is empty in the current record.", {"OK"}, 1, 0, true)
  56.         return false
  57.     end if
  58.     return the_value
  59. end get_cell_value
  60.  
  61. on choose_cell(the_cell_label)
  62.     tell application "FileMaker Pro"
  63.         if (exists of (document 1)) = false then
  64.             my dd("There is no database open.", {"OK"}, 1, 0, true)
  65.             return false
  66.         end if
  67.         set the_cell_names to name of cells of current record
  68.     end tell
  69.     set cell_name to (choose from list the_cell_names with prompt "Which cell should I use for " & the_cell_label & "?") as Unicode text
  70.     if cell_name = "false" then return false
  71.     return cell_name
  72. end choose_cell
  73.  
  74. property JPT_app_name : "Jon's Phone Tool"
  75. property JPT_app_code : "jJPT"
  76. property JPT_app : ""
  77.  
  78. on dial_number(the_number, the_name)
  79.     my find_JPT()
  80.     using terms from application "Jon's Phone Tool"
  81.         if JPT_app ≠ "" then
  82.             tell application JPT_app
  83.                 if the_name = "" then
  84.                     dial number the_number
  85.                 else
  86.                     dial number the_number name the_name
  87.                 end if
  88.             end tell
  89.         end if
  90.     end using terms from
  91. end dial_number
  92.  
  93. on find_JPT()
  94.     try
  95.         get JPT_app as alias
  96.         return
  97.     on error
  98.         set JPT_app to ""
  99.     end try
  100.     tell application "System Events" to set the_process to {} & (processes whose creator type = JPT_app_code)
  101.     if the_process ≠ {} then
  102.         set JPT_app to (file of item 1 of the_process) as alias as Unicode text
  103.     else
  104.         try
  105.             tell application "Finder" to set the_process to application file id JPT_app_code as alias
  106.             set JPT_app to the_process as Unicode text
  107.         on error
  108.             set app_folder to (path to applications folder from local domain) as Unicode text
  109.             try
  110.                 set the_process to app_folder & JPT_app_name & ".app" as alias
  111.                 set JPT_app to the_process as Unicode text
  112.             on error
  113.                 try
  114.                     set the_process to app_folder & "Utilities:" & JPT_app_name & ".app" as alias
  115.                     set JPT_app to the_process as Unicode text
  116.                 end try
  117.             end try
  118.         end try
  119.         if JPT_app = "" then
  120.             try
  121.                 activate
  122.                 set JPT_app to (choose file of type {"APPL"} with prompt "Please locate " & JPT_app_name) as Unicode text
  123.             on error
  124.                 set JPT_app to ""
  125.             end try
  126.         end if
  127.     end if
  128. end find_JPT
  129.